/*     */ package com.zimbra.cs.mailbox.calendar;
/*     */ 
/*     */ import com.zimbra.common.calendar.TimeZoneMap;
/*     */ import com.zimbra.common.calendar.ZCalendar.ICalTok;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.cs.mailbox.Metadata;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class InviteInfo
/*     */   implements Comparable<InviteInfo>, Cloneable
/*     */ {
/*     */   private int mMsgId;
/*     */   private int mComponentId;
/*     */   private RecurId mRecurrenceId;
/*     */   private String mMethod;
/*     */   private static final String FN_MSGID = "i";
/*     */   private static final String FN_COMPNUM = "c";
/*     */   private static final String FN_RECURRENCEID = "r";
/*     */   private static final String FN_METHOD = "m";
/*     */   private static final int METHOD_REQUEST = 3;
/*     */   private static final int METHOD_CANCEL = 4;
/*     */   
/*     */   public InviteInfo(Invite inv)
/*     */   {
/*  36 */     this.mMsgId = inv.getMailItemId();
/*  37 */     this.mComponentId = inv.getComponentNum();
/*  38 */     this.mRecurrenceId = inv.getRecurId();
/*  39 */     this.mMethod = inv.getMethod();
/*     */   }
/*     */   
/*     */   private InviteInfo(int msgId, int componentId, RecurId recurrenceId, String method) {
/*  43 */     this.mMsgId = msgId;
/*  44 */     this.mComponentId = componentId;
/*  45 */     this.mRecurrenceId = recurrenceId;
/*  46 */     this.mMethod = method;
/*     */   }
/*     */   
/*     */   public boolean equals(Object o) {
/*  50 */     if (!(o instanceof InviteInfo)) return false;
/*  51 */     InviteInfo other = (InviteInfo)o;
/*  52 */     return (this.mMsgId == other.mMsgId) && (this.mComponentId == other.mComponentId) && (StringUtil.equal(this.mMethod, other.mMethod)) && (((this.mRecurrenceId == null) && (other.mRecurrenceId == null)) || ((this.mRecurrenceId != null) && (this.mRecurrenceId.equals(other.mRecurrenceId))));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public int compareTo(InviteInfo other)
/*     */   {
/*  61 */     if (other == null) return 1;
/*  62 */     int toRet = this.mMsgId - other.mMsgId;
/*  63 */     if (toRet == 0) {
/*  64 */       toRet = this.mComponentId - other.mComponentId;
/*  65 */       if (toRet == 0) {
/*  66 */         String rid = this.mRecurrenceId != null ? this.mRecurrenceId.toString() : null;
/*  67 */         String ridOther = other.mRecurrenceId != null ? other.mRecurrenceId.toString() : null;
/*  68 */         toRet = StringUtil.compareTo(rid, ridOther);
/*  69 */         if (toRet == 0)
/*  70 */           toRet = StringUtil.compareTo(this.mMethod, other.mMethod);
/*     */       }
/*     */     }
/*  73 */     return toRet;
/*     */   }
/*     */   
/*     */   public Object clone() {
/*  77 */     RecurId rid = this.mRecurrenceId != null ? (RecurId)this.mRecurrenceId.clone() : null;
/*  78 */     return new InviteInfo(this.mMsgId, this.mComponentId, rid, this.mMethod);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static InviteInfo fromMetadata(Metadata md, TimeZoneMap tzmap)
/*     */     throws ServiceException
/*     */   {
/*  91 */     RecurId recurrenceId = null;
/*  92 */     int methodInt = 0;
/*  93 */     String method = ZCalendar.ICalTok.REQUEST.toString();
/*     */     
/*  95 */     int msgId = (int)md.getLong("i");
/*  96 */     int compNum = (int)md.getLong("c");
/*     */     
/*  98 */     methodInt = (int)md.getLong("m");
/*  99 */     switch (methodInt) {
/*     */     case 4: 
/* 101 */       method = ZCalendar.ICalTok.CANCEL.toString();
/*     */     }
/*     */     
/* 104 */     if (md.containsKey("r")) {
/* 105 */       recurrenceId = RecurId.decodeMetadata(md.getMap("r"), tzmap);
/*     */     }
/*     */     
/* 108 */     return new InviteInfo(msgId, compNum, recurrenceId, method);
/*     */   }
/*     */   
/*     */   public Metadata encodeMetadata() {
/* 112 */     Metadata md = new Metadata();
/* 113 */     md.put("i", this.mMsgId);
/* 114 */     md.put("c", this.mComponentId);
/* 115 */     if (this.mRecurrenceId != null) {
/* 116 */       md.put("r", this.mRecurrenceId.encodeMetadata());
/*     */     }
/*     */     
/* 119 */     if (this.mMethod.equals(ZCalendar.ICalTok.CANCEL.toString())) {
/* 120 */       md.put("m", 4L);
/*     */     } else {
/* 122 */       md.put("m", 3L);
/*     */     }
/*     */     
/* 125 */     return md;
/*     */   }
/*     */   
/*     */   public String toString() {
/* 129 */     return this.mMsgId + "-" + this.mComponentId + "-" + this.mMethod + "-" + this.mRecurrenceId;
/*     */   }
/*     */   
/*     */   public int getMsgId() {
/* 133 */     return this.mMsgId;
/*     */   }
/*     */   
/*     */   public int getComponentId() {
/* 137 */     return this.mComponentId;
/*     */   }
/*     */   
/* 140 */   public boolean hasRecurrenceId() { return this.mRecurrenceId != null; }
/*     */   
/*     */   public RecurId getRecurrenceId() {
/* 143 */     return this.mRecurrenceId;
/*     */   }
/*     */   
/*     */   public String getMethod() {
/* 147 */     return this.mMethod;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/calendar/InviteInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */